package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.service.OrdersProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单-商品关系表(OrdersProduct)表控制层
 *
 * @author makejava
 * @since 2024-01-13 17:16:26
 */
@RestController
@RequestMapping("/ordersProduct")
public class OrdersProductController {
    /**
     * 服务对象
     */
    @Autowired
    private OrdersProductService ordersProductService;


    @PostMapping("/selectByPageInStore")
    public Result selectByPageInStore(@RequestParam("currentPage") Integer currentPage,
                                      @RequestParam("pageSize") Integer pageSize,
                                      @RequestParam("storeId") Integer storeId) {
        return Result.success(ordersProductService.selectByPageInStore(currentPage, pageSize, storeId));
    }

    @PostMapping("/loadByOrderId")
    public Result loadByOrderId(@RequestParam("orderId") Integer orderId) {
        return Result.success(ordersProductService.loadByOrderId(orderId));
    }

    @PostMapping("/selectByPage")
    public Result selectByPage(@RequestParam("currentPage") Integer currentPage,
                               @RequestParam("pageSize") Integer pageSize) {
        return Result.success(ordersProductService.selectByPage(currentPage, pageSize));
    }

    @PostMapping("/selectByManyCondition")
    public Result selectByManyCondition(@RequestParam("currentPage") Integer currentPage,
                                        @RequestParam("pageSize") Integer pageSize,
                                        @RequestParam(value = "number", required = false) String number,
                                        @RequestParam(value = "storeId", required = false) Integer storeId,
                                        @RequestParam(value = "userId", required = false) Integer userId,
                                        @RequestParam(value = "startTime", required = false) String startTime,
                                        @RequestParam(value = "endTime", required = false) String endTime,
                                        @RequestParam(value = "status", required = false) Integer status) {
        return Result.success(ordersProductService.selectByManyCondition(currentPage, pageSize, number, storeId, userId, startTime, endTime, status));

    }


    @PostMapping("/confirmReceipt")

    public Result confirmReceipt(@RequestParam("id") Integer id) {
        ordersProductService.confirmReceipt(id);
        return Result.success("确认收货成功");
    }


    @PostMapping("/send")
    public Result send(@RequestParam("id") Integer id) {
        ordersProductService.send(id);
        return Result.success("发货成功");
    }

    @PostMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        ordersProductService.deleteById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        ordersProductService.deleteByIds(ids);
        return Result.success("删除成功！");
    }
}

